/**
 * @author Ahammer
 * @date   2009 03
 * @update 2010 01 RGBtoHSV, RGBtoHLS,HSVtoRGB, HLStoRGB, 
 */

/*
 * This file is part of Iqm.
 * Copyright (c) 2010-2011 Helmut Ahammer
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package opgui;

import java.awt.GridBagConstraints;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.media.jai.ParameterBlockJAI;
import javax.media.jai.PlanarImage;
import javax.swing.ButtonGroup;
import javax.swing.JRadioButtonMenuItem;
import javax.swing.JToolBar;
import javax.swing.SwingUtilities;
import main.IqmTools;
import main.Tank;


public class IqmConvertGUI extends IqmOperatorJFrame implements IqmOperatorGUIBuilder, 
																ActionListener {

	private   ParameterBlockJAI  pbJAI      = null;  //  @jve:decl-index=0:
	//public  ImgProcFuncJFrame  opGUIFrame = null;
	//private IqmConvertGUI      opGUIFrame = null;  //actionPerformed events werden in dieser Klasse abgehandelt
	
	private  JRadioButtonMenuItem   butt8toRGB    = null;
	private  JRadioButtonMenuItem   butt8to16     = null;
	private  JRadioButtonMenuItem   butt8Hidden   = null;
	
	private  JRadioButtonMenuItem   butt16to8     = null;
	private  JRadioButtonMenuItem   butt16Hidden  = null;

	private  JRadioButtonMenuItem   buttPaletteToRGB  = null;
	private  JRadioButtonMenuItem   buttPaletteHidden = null;
	
	private JRadioButtonMenuItem   buttNTSC        = null;
	private JRadioButtonMenuItem   buttMeanRGB     = null;
	private JRadioButtonMenuItem   buttChR         = null;
	private JRadioButtonMenuItem   buttChG         = null;
	private JRadioButtonMenuItem   buttChB         = null;
	private JRadioButtonMenuItem   buttRGB2HSV     = null;
	private JRadioButtonMenuItem   buttRGB2HLS     = null;
	private JRadioButtonMenuItem   buttRGB2CIELAB  = null;
	private JRadioButtonMenuItem   buttRGB2CIELUV  = null;
	private JRadioButtonMenuItem   buttRGB2CIEXYZ  = null;
	private JRadioButtonMenuItem   buttHSV2RGB     = null;
	private JRadioButtonMenuItem   buttHLS2RGB     = null;
	private JRadioButtonMenuItem   buttCIELAB2RGB  = null;
	private JRadioButtonMenuItem   buttCIELUV2RGB  = null;
	private JRadioButtonMenuItem   buttCIEXYZ2RGB  = null;
	private JRadioButtonMenuItem   buttRGBHidden   = null;

	private JToolBar               jToolBar8bit 	 = null;
	private JToolBar               jToolBar16bit	 = null;
	private JToolBar 			   jToolBarPalettte  = null;
	private JToolBar               jToolBarRGB       = null;
	
	private ButtonGroup            buttGroup8bit     = null;
	private ButtonGroup            buttGroup16bit    = null;
	private ButtonGroup            buttGroupRGB      = null;
	private ButtonGroup			   buttGroupPalettte = null;
	

	/**
	 * This method sets the current parameter block to the argument
	 * @param ParameterBlockJAI pbJAI
	 *
	 */
	@Override
	public void setParameterBlock(ParameterBlockJAI arg){
		pbJAI = arg;
		IqmTools.setCurrParameterBlockJAI(pbJAI);	
	}
	/**
	 * This method sets the current parameter block
	 * The individual values of the GUI  current ParameterBlock
	 *
	 */
	@Override
	public void setParameterBlock(){
		if (pbJAI == null) System.out.println("IqmConverGUI: pbJAI ist null");
		if (butt8toRGB.isSelected())  		pbJAI.setParameter("Options8bit", 0);
		if (butt8to16.isSelected())   		pbJAI.setParameter("Options8bit", 1);
		if (butt16to8.isSelected())   		pbJAI.setParameter("Options16bit", 0);
		if (buttPaletteToRGB.isSelected())  pbJAI.setParameter("OptionsPalette", 0);
		if (buttNTSC.isSelected())    		pbJAI.setParameter("OptionsRGB", 0);
		if (buttMeanRGB.isSelected()) 		pbJAI.setParameter("OptionsRGB", 1);
		if (buttChR.isSelected())     		pbJAI.setParameter("OptionsRGB", 2);
		if (buttChG.isSelected())     		pbJAI.setParameter("OptionsRGB", 3);
		if (buttChB.isSelected())     		pbJAI.setParameter("OptionsRGB", 4);
		if (buttRGB2HSV.isSelected())     	pbJAI.setParameter("OptionsRGB", 5);
		if (buttRGB2HLS.isSelected())     	pbJAI.setParameter("OptionsRGB", 6);
		if (buttRGB2CIELAB.isSelected())    pbJAI.setParameter("OptionsRGB", 7);
		if (buttRGB2CIELUV.isSelected())    pbJAI.setParameter("OptionsRGB", 8);
		if (buttRGB2CIEXYZ.isSelected())    pbJAI.setParameter("OptionsRGB", 9);
		if (buttHSV2RGB.isSelected())     	pbJAI.setParameter("OptionsRGB", 10);
		if (buttHLS2RGB.isSelected())     	pbJAI.setParameter("OptionsRGB", 11);
		if (buttCIELAB2RGB.isSelected())    pbJAI.setParameter("OptionsRGB", 12);
		if (buttCIELUV2RGB.isSelected())    pbJAI.setParameter("OptionsRGB", 13);
		if (buttCIEXYZ2RGB.isSelected())    pbJAI.setParameter("OptionsRGB", 14);
		IqmTools.setCurrParameterBlockJAI(pbJAI);	
	}
	/**
	 * This method sets the current parameter values
	 */
	@Override
	public void setParameterValues(){
		int idx = IqmTools.getCurrManagerImgIndex();
	    PlanarImage pi = Tank.getCurrentTankImageAt(idx); 
	       if (pi == null){
	    	   System.out.println("IqmConvertGUI: Current image not defined");
	    	   return;
	       }
	    //int pixelSize = pi.getColorModel().getPixelSize();
        //int numBands  = pi.getNumBands(); 
        //String type = IqmTools.getImgTyp(pixelSize, numBands);
        String type = IqmTools.getImgTyp(pi);
	
		butt8Hidden.setSelected(true);
		butt16Hidden.setSelected(true);
		buttPaletteHidden.setSelected(true);
		buttRGBHidden.setSelected(true);

		
		butt8toRGB.setEnabled(false);
		butt8to16.setEnabled(false);
		butt16to8.setEnabled(false);
		buttPaletteToRGB.setEnabled(false);
		buttNTSC.setEnabled(false);
		buttMeanRGB.setEnabled(false);
		buttChR.setEnabled(false);
		buttChG.setEnabled(false);
		buttChB.setEnabled(false);
		buttRGB2HSV.setEnabled(false);
		buttRGB2HLS.setEnabled(false);
		buttRGB2CIELAB.setEnabled(false);
		buttRGB2CIELUV.setEnabled(false);
		buttRGB2CIEXYZ.setEnabled(false);
		buttHSV2RGB.setEnabled(false);
		buttHLS2RGB.setEnabled(false);
		buttCIELAB2RGB.setEnabled(false);
		buttCIELUV2RGB.setEnabled(false);
		buttCIEXYZ2RGB.setEnabled(false);
		
		if (type.equals("8 bit")){ 
			if (pbJAI.getIntParameter("Options8bit") == 0 )  butt8toRGB.setSelected(true);
			if (pbJAI.getIntParameter("Options8bit") == 1 )  butt8to16.setSelected(true);
			butt8toRGB.setEnabled(true);
			butt8to16.setEnabled(true);
		}
		if (type.equals("16 bit")){ 
			if (pbJAI.getIntParameter("Options16bit") == 0 )  butt16to8.setSelected(true);
			butt16to8.setEnabled(true);
		}
		if (type.equals("Palette")){ 
			if (pbJAI.getIntParameter("OptionsPalette") == 0 )  buttPaletteToRGB.setSelected(true);
			buttPaletteToRGB.setEnabled(true);
		}
		if (type.equals("RGB")){ 
			if (pbJAI.getIntParameter("OptionsRGB") == 0 )  buttNTSC.setSelected(true);
			if (pbJAI.getIntParameter("OptionsRGB") == 1 )  buttMeanRGB.setSelected(true);		
			if (pbJAI.getIntParameter("OptionsRGB") == 2 )  buttChR.setSelected(true);		
			if (pbJAI.getIntParameter("OptionsRGB") == 3 )  buttChG.setSelected(true);		
			if (pbJAI.getIntParameter("OptionsRGB") == 4 )  buttChB.setSelected(true);
			if (pbJAI.getIntParameter("OptionsRGB") == 5 )  buttRGB2HSV.setSelected(true);
			if (pbJAI.getIntParameter("OptionsRGB") == 6 )  buttRGB2HLS.setSelected(true);
			if (pbJAI.getIntParameter("OptionsRGB") == 7 )  buttRGB2CIELAB.setSelected(true);
			if (pbJAI.getIntParameter("OptionsRGB") == 8 )  buttRGB2CIELUV.setSelected(true);
			if (pbJAI.getIntParameter("OptionsRGB") == 9 )  buttRGB2CIEXYZ.setSelected(true);
			if (pbJAI.getIntParameter("OptionsRGB") == 10 ) buttHSV2RGB.setSelected(true);
			if (pbJAI.getIntParameter("OptionsRGB") == 11 ) buttHLS2RGB.setSelected(true);
			if (pbJAI.getIntParameter("OptionsRGB") == 12 ) buttCIELAB2RGB.setSelected(true);
			if (pbJAI.getIntParameter("OptionsRGB") == 13 ) buttCIELUV2RGB.setSelected(true);
			if (pbJAI.getIntParameter("OptionsRGB") == 14 ) buttCIEXYZ2RGB.setSelected(true);
			buttNTSC.setEnabled(true);
			buttMeanRGB.setEnabled(true);
			buttChR.setEnabled(true);
			buttChG.setEnabled(true);
			buttChB.setEnabled(true);
			buttRGB2HSV.setEnabled(true);
			buttRGB2HLS.setEnabled(true);
			buttRGB2CIELAB.setEnabled(true);
			buttRGB2CIELUV.setEnabled(true);
			buttRGB2CIEXYZ.setEnabled(true);
			buttHSV2RGB.setEnabled(true);
			buttHLS2RGB.setEnabled(true);
			buttCIELAB2RGB.setEnabled(true);
			buttCIELUV2RGB.setEnabled(true);
			buttCIEXYZ2RGB.setEnabled(true);
		}
	}
	/**
	 * constructor
	 */
	public IqmConvertGUI() {
		super();
	}
	/**
	 * This method creates and shows the GUI
	 * 
	 * @return void
	 */
	@Override
	public void createIqmOperatorGUI() {
		//opGUIFrame = new IqmConvertGUI();      //actionPerforemd events werden in dieser Klasse abgehandelt
		//opGUIFrame.getJContentPane();
		this.initialize(); //Aufruf von ImgProcFuncJFrame
		this.setTitle("Convert");  
		//Dimension dim = this.getSize();
		//this.setSize(dim.width, dim.height+230);
		this.getJContentPane().add(getJToolBar8bit(),    getGridBagConstraintsButtonGroup8bit());
		this.getJContentPane().add(getJToolBar16bit(),   getGridBagConstraintsButtonGroup16bit());
		this.getJContentPane().add(getJToolBarPalette(), getGridBagConstraintsButtonGroupPalette());
		this.getJContentPane().add(getJToolBarRGB(),     getGridBagConstraintsButtonGroupRGB());
		this.pack();
		//this.repaint();
		if (pbJAI == null) pbJAI = new ParameterBlockJAI("iqmconvert");  //nur wenn das erste mal aufgerufen
		//pbJAI = new ParameterBlockJAI("iqmconvert"); //immer der default Block
		IqmTools.setCurrParameterBlockJAI(pbJAI);
		setParameterValues();
	}
	private  GridBagConstraints getGridBagConstraintsButtonGroup8bit(){
		GridBagConstraints gridBagConstraintsButtonGroup8bit = new GridBagConstraints();
		gridBagConstraintsButtonGroup8bit.gridx = 1;
		gridBagConstraintsButtonGroup8bit.gridy = 4;
		gridBagConstraintsButtonGroup8bit.gridwidth = 3;
		gridBagConstraintsButtonGroup8bit.insets = new Insets(10,15,0,15);
		gridBagConstraintsButtonGroup8bit.fill = GridBagConstraints.BOTH;
		return gridBagConstraintsButtonGroup8bit;
	}
	private  GridBagConstraints getGridBagConstraintsButtonGroup16bit(){
		GridBagConstraints gridBagConstraintsButtonGroup16bit = new GridBagConstraints();
		gridBagConstraintsButtonGroup16bit.gridx = 1;
		gridBagConstraintsButtonGroup16bit.gridy = 5;
		gridBagConstraintsButtonGroup16bit.gridwidth = 3;
		gridBagConstraintsButtonGroup16bit.insets = new Insets(10,15,0,15);
		gridBagConstraintsButtonGroup16bit.fill = GridBagConstraints.BOTH;
		return gridBagConstraintsButtonGroup16bit;
	}
	private  GridBagConstraints getGridBagConstraintsButtonGroupPalette(){
		GridBagConstraints gridBagConstraintsButtonGroupPalette = new GridBagConstraints();
		gridBagConstraintsButtonGroupPalette.gridx = 1;
		gridBagConstraintsButtonGroupPalette.gridy = 6;
		gridBagConstraintsButtonGroupPalette.gridwidth = 3;
		gridBagConstraintsButtonGroupPalette.insets = new Insets(10,15,0,15);
		gridBagConstraintsButtonGroupPalette.fill = GridBagConstraints.BOTH;
		return gridBagConstraintsButtonGroupPalette;
	}
	private  GridBagConstraints getGridBagConstraintsButtonGroupRGB(){
		GridBagConstraints gridBagConstraintsButtonGroupRGB = new GridBagConstraints();
		gridBagConstraintsButtonGroupRGB.gridx = 1;
		gridBagConstraintsButtonGroupRGB.gridy = 7;
		gridBagConstraintsButtonGroupRGB.gridwidth = 3;
		gridBagConstraintsButtonGroupRGB.insets = new Insets(10,15,20,15);
		gridBagConstraintsButtonGroupRGB.fill = GridBagConstraints.BOTH;
		return gridBagConstraintsButtonGroupRGB;
	}

	/**
	 * This method updates the GUI if needed
	 * This method overrides IqmOperatorJFrame
	 */
	public void updateIqmOperatorGUI(){
	
	}
	
	/**
	 * This method initializes the Option: 8bit to RGB	
	 * 	
	 * @return javax.swing.JRadioButtonMenuItem	
	 */
	private  JRadioButtonMenuItem getJRadioButtonMenuButt8toRGB() {
		//if (butt8toRGB == null) {
			butt8toRGB  = new JRadioButtonMenuItem();
			butt8toRGB .setText("8bit to RGB");
			butt8toRGB .setToolTipText("reforms a 8bit image to a RGB 24bit color image");
			butt8toRGB .addActionListener(this);
			butt8toRGB .setActionCommand("parameter");
		//}
		return butt8toRGB;
	}
	/**
	 * This method initializes the Option: 8bit to 16bit	
	 * 	
	 * @return javax.swing.JRadioButtonMenuItem	
	 */
	private  JRadioButtonMenuItem getJRadioButtonMenuButt8to16() {
		//if (butt8to16 == null) {
			butt8to16  = new JRadioButtonMenuItem();
			butt8to16 .setText("8bit to 16bit");
			butt8to16 .setToolTipText("reforms a 8bit image to 16bit");
			butt8to16 .addActionListener(this);
			butt8to16 .setActionCommand("parameter");
		//}
		return butt8to16;
	}
	/**
	 * This method initializes the hidden 8bit option	
	 * 	
	 * @return javax.swing.JRadioButtonMenuItem	
	 */
	private  JRadioButtonMenuItem getJRadioButtonMenuButt8Hidden() {
		//if (butt8Hidden == null) {
			butt8Hidden  = new JRadioButtonMenuItem();
			butt8Hidden .setText("Hidden");
			butt8Hidden.setVisible(false);
		//}
		return butt8Hidden;
	}
	/**
	 * This method initializes the Option: 16bit to 8bit	
	 * 	
	 * @return javax.swing.JRadioButtonMenuItem	
	 */
	private  JRadioButtonMenuItem getJRadioButtonMenuButt16to8() {
		//if (butt16to8 == null) {
			butt16to8  = new JRadioButtonMenuItem();
			butt16to8 .setText("16bit to 8bit");
			butt16to8 .setToolTipText("reforms a 16bit image to 8bit");
			butt16to8 .addActionListener(this);
			butt16to8 .setActionCommand("parameter");
		//}
		return butt16to8;
	}
	/**
	 * This method initializes the hidden 16bit option	
	 * 	
	 * @return javax.swing.JRadioButtonMenuItem	
	 */
	private  JRadioButtonMenuItem getJRadioButtonMenuButt16Hidden() {
		//if (butt16Hidden == null) {
			butt16Hidden  = new JRadioButtonMenuItem();
			butt16Hidden .setText("Hidden");
			butt16Hidden.setVisible(false);
		//}
		return butt16Hidden;
	}

	/**
	 * This method initializes the Option: 16bit to 8bit	
	 * 	
	 * @return javax.swing.JRadioButtonMenuItem	
	 */
	private  JRadioButtonMenuItem getJRadioButtonMenuButtPaletteToRGB() {
		//if (buttPaletteToRGB == null) {
			buttPaletteToRGB  = new JRadioButtonMenuItem();
			buttPaletteToRGB .setText("Palette to RGB");
			buttPaletteToRGB .setToolTipText("reforms a Palette (indexed) image to RGB");
			buttPaletteToRGB .addActionListener(this);
			buttPaletteToRGB .setActionCommand("parameter");
		//}
		return buttPaletteToRGB;
	}
	/**
	 * This method initializes the hidden 16bit option	
	 * 	
	 * @return javax.swing.JRadioButtonMenuItem	
	 */
	private  JRadioButtonMenuItem getJRadioButtonMenuButtPaletteHidden() {
		//if (buttPaletteHidden == null) {
			buttPaletteHidden  = new JRadioButtonMenuItem();
			buttPaletteHidden .setText("Hidden");
			buttPaletteHidden.setVisible(false);

		//}
		return buttPaletteHidden;
	}	
	/**
	 * This method initializes the Option: NTSC	
	 * 	
	 * @return javax.swing.JRadioButtonMenuItem	
	 */
	private  JRadioButtonMenuItem getJRadioButtonMenuButtNTSC() {
		//if (buttNTSC == null) {
			buttNTSC  = new JRadioButtonMenuItem();
			buttNTSC .setText("NTSC Luminance: 29.9%R  58.7%G  11.4%B");
			buttNTSC .setToolTipText("calculates the NTSC luminance");
			buttNTSC .addActionListener(this);
			buttNTSC .setActionCommand("parameter");
		//}
		return buttNTSC ;
	}
	/**
	 * This method initializes the Option: Mean of RGB	
	 * 	
	 * @return javax.swing.JRadioButtonMenuItem	
	 */
	private  JRadioButtonMenuItem getJRadioButtonMenuButtMeanRGB() {
		//if (buttMeanRGB == null) {
			buttMeanRGB = new JRadioButtonMenuItem();
			buttMeanRGB.setText("RGB Mean");
			buttMeanRGB.setToolTipText("calculates the mean of RGB channels");
			buttMeanRGB.addActionListener(this);
			buttMeanRGB.setActionCommand("parameter");
		//}
		return buttMeanRGB;
	}

	/**
	 * This method initializes the Option: Extract red channel 	
	 * 	
	 * @return javax.swing.JRadioButtonMenuItem	
	 */
	private  JRadioButtonMenuItem getJRadioButtonMenuButtChR() {
		//if (buttChR == null) {
			buttChR = new JRadioButtonMenuItem();
			buttChR.setText("extract R");
			buttChR.setToolTipText("extracts the red channel");
			buttChR.addActionListener(this);
			buttChR.setActionCommand("parameter");
		//}
		return buttChR;
	}
	/**
	 * This method initializes the Option: Extract the green channel	
	 * 	
	 * @return javax.swing.JRadioButtonMenuItem	
	 */
	private  JRadioButtonMenuItem getJRadioButtonMenuButtChG() {
		//if (buttChG == null) {
			buttChG = new JRadioButtonMenuItem();
			buttChG.setText("extract G");
			buttChG.setToolTipText("extracts the green channel");
			buttChG.addActionListener(this);
			buttChG.setActionCommand("parameter");
		//}
		return buttChG;
	}
	/**
	 * This method initializes the Option: Extract the blue channel	
	 * 	
	 * @return javax.swing.JRadioButtonMenuItem	
	 */
	private  JRadioButtonMenuItem getJRadioButtonMenuButtChB() {
		//if (buttChB == null) {
			buttChB = new JRadioButtonMenuItem();
			buttChB.setText("extract B");
			buttChB.setToolTipText("extracts the blue channel");
			buttChB.addActionListener(this);
			buttChB.setActionCommand("parameter");
		//}
		return buttChB;
	}
	
	/**
	 * This method initializes the Option: RGB2HSV conversion
	 * 	
	 * @return javax.swing.JRadioButtonMenuItem	
	 */
	private  JRadioButtonMenuItem getJRadioButtonMenuButtRGB2HSV() {
		//if (buttRGB2HSV== null) {
			buttRGB2HSV= new JRadioButtonMenuItem();
			buttRGB2HSV.setText("RGB to HSV");
			buttRGB2HSV.setToolTipText("converts to the HSV color space");
			buttRGB2HSV.addActionListener(this);
			buttRGB2HSV.setActionCommand("parameter");
		//}
		return buttRGB2HSV;
	}
	
	/**
	 * This method initializes the Option: RGB2HLS conversion	
	 * 	
	 * @return javax.swing.JRadioButtonMenuItem	
	 */
	private  JRadioButtonMenuItem getJRadioButtonMenuButtRGB2HLS() {
		//if (buttRGB2HLS == null) {
			buttRGB2HLS = new JRadioButtonMenuItem();
			buttRGB2HLS.setText("RGB to HLS");
			buttRGB2HLS.setToolTipText("converts to the HLS color space");
			buttRGB2HLS.addActionListener(this);
			buttRGB2HLS.setActionCommand("parameter");
		//}
		return buttRGB2HLS;
	}
	/**
	 * This method initializes the Option: RGB2CIELAB conversion	
	 * 	
	 * @return javax.swing.JRadioButtonMenuItem	
	 */
	private  JRadioButtonMenuItem getJRadioButtonMenuButtRGB2CIELAB() {
		//if (buttRGB2CIELAB == null) {
			buttRGB2CIELAB = new JRadioButtonMenuItem();
			buttRGB2CIELAB.setText("RGB to CIELAB");
			buttRGB2CIELAB.setToolTipText("converts to the CIELAB color space");
			buttRGB2CIELAB.addActionListener(this);
			buttRGB2CIELAB.setActionCommand("parameter");
		//}
		return buttRGB2CIELAB;
	}
	/**
	 * This method initializes the Option: RGB2CIELUV conversion	
	 * 	
	 * @return javax.swing.JRadioButtonMenuItem	
	 */
	private  JRadioButtonMenuItem getJRadioButtonMenuButtRGB2CIELUV() {
		//if (buttRGB2CIELUV == null) {
			buttRGB2CIELUV = new JRadioButtonMenuItem();
			buttRGB2CIELUV.setText("RGB to CIELUV");
			buttRGB2CIELUV.setToolTipText("converts to the CIELUV color space");
			buttRGB2CIELUV.addActionListener(this);
			buttRGB2CIELUV.setActionCommand("parameter");
		//}
		return buttRGB2CIELUV;
	}
	/**
	 * This method initializes the Option: RGB2CIEXYZ conversion	
	 * 	
	 * @return javax.swing.JRadioButtonMenuItem	
	 */
	private  JRadioButtonMenuItem getJRadioButtonMenuButtRGB2CIEXYZ() {
		//if (buttRGB2CIEXYZ == null) {
			buttRGB2CIEXYZ = new JRadioButtonMenuItem();
			buttRGB2CIEXYZ.setText("RGB to CIEXYZ");
			buttRGB2CIEXYZ.setToolTipText("converts to the CIEXYZ color space");
			buttRGB2CIEXYZ.addActionListener(this);
			buttRGB2CIEXYZ.setActionCommand("parameter");
		//}
		return buttRGB2CIEXYZ;
	}
	/**
	 * This method initializes the Option: HSV2RGB conversion	
	 * 	
	 * @return javax.swing.JRadioButtonMenuItem	
	 */
	private  JRadioButtonMenuItem getJRadioButtonMenuButtHSV2RGB() {
		//if (buttHSV2RGB == null) {
			buttHSV2RGB = new JRadioButtonMenuItem();
			buttHSV2RGB.setText("HSV to RGB");
			buttHSV2RGB.setToolTipText("converts the HSV color space to RGB");
			buttHSV2RGB.addActionListener(this);
			buttHSV2RGB.setActionCommand("parameter");
		//}
		return buttHSV2RGB;
	}
	/**
	 * This method initializes the Option: HLS2RGB conversion	
	 * 	
	 * @return javax.swing.JRadioButtonMenuItem	
	 */
	private  JRadioButtonMenuItem getJRadioButtonMenuButtHLS2RGB() {
		//if (buttHLS2RGB == null) {
			buttHLS2RGB = new JRadioButtonMenuItem();
			buttHLS2RGB.setText("HLS to RGB");
			buttHLS2RGB.setToolTipText("converts the HLS color space to RGB");
			buttHLS2RGB.addActionListener(this);
			buttHLS2RGB.setActionCommand("parameter");
		//}
		return buttHLS2RGB;
	}
	/**
	 * This method initializes the Option: CIELAB2RGB conversion	
	 * 	
	 * @return javax.swing.JRadioButtonMenuItem	
	 */
	private  JRadioButtonMenuItem getJRadioButtonMenuButtCIELAB2RGB() {
		//if (buttCIELAB2RGB == null) {
			buttCIELAB2RGB = new JRadioButtonMenuItem();
			buttCIELAB2RGB.setText("CIELAB to RGB");
			buttCIELAB2RGB.setToolTipText("converts the CIELAB color space to RGB");
			buttCIELAB2RGB.addActionListener(this);
			buttCIELAB2RGB.setActionCommand("parameter");
		//}
		return buttCIELAB2RGB;
	}
	/**
	 * This method initializes the Option: CIELUV2RGB conversion	
	 * 	
	 * @return javax.swing.JRadioButtonMenuItem	
	 */
	private  JRadioButtonMenuItem getJRadioButtonMenuButtCIELUV2RGB() {
		//if (buttCIELUV2RGB == null) {
			buttCIELUV2RGB = new JRadioButtonMenuItem();
			buttCIELUV2RGB.setText("CIELUV to RGB");
			buttCIELUV2RGB.setToolTipText("converts the CIELUV color space to RGB");
			buttCIELUV2RGB.addActionListener(this);
			buttCIELUV2RGB.setActionCommand("parameter");
		//}
		return buttCIELUV2RGB;
	}
	/**
	 * This method initializes the Option: CIEXYZ2RGB conversion	
	 * 	
	 * @return javax.swing.JRadioButtonMenuItem	
	 */
	private  JRadioButtonMenuItem getJRadioButtonMenuButtCIEXYZ2RGB() {
		//if (buttCIEXYZ2RGB == null) {
			buttCIEXYZ2RGB = new JRadioButtonMenuItem();
			buttCIEXYZ2RGB.setText("CIEXYZ to RGB");
			buttCIEXYZ2RGB.setToolTipText("converts the CIEXYZ color space to RGB");
			buttCIEXYZ2RGB.addActionListener(this);
			buttCIEXYZ2RGB.setActionCommand("parameter");
		//}
		return buttCIEXYZ2RGB;
	}
	
	/**
	 * This method initializes the hidden RGB option	
	 * 	
	 * @return javax.swing.JRadioButtonMenuItem	
	 */
	private  JRadioButtonMenuItem getJRadioButtonMenuButtRGBHidden() {
		//if (buttRGBHidden == null) {
			buttRGBHidden  = new JRadioButtonMenuItem();
			buttRGBHidden .setText("Hidden");
			buttRGBHidden.setVisible(false);

		//}
		return buttRGBHidden;
	}
	/**
	 * This method initializes jJToolBarBar	
	 * 	
	 * @return javax.swing.JToolBar	
	 */
	private   JToolBar getJToolBar8bit() {
//		if (jToolBar8bit == null) {
			jToolBar8bit = new JToolBar("Options");
			jToolBar8bit.setOrientation(1); //Vertical orientation
			jToolBar8bit.add(getJRadioButtonMenuButt8toRGB());			
			jToolBar8bit.add(getJRadioButtonMenuButt8to16());
			jToolBar8bit.add(getJRadioButtonMenuButt8Hidden());
			//jToolBar8bit.addSeparator();
			this.setButtonGroup8bit();	//Gruppieren der JRadioButtons
//		}
		return jToolBar8bit;
	}
	/**
	 * This method initializes jJToolBarBar	
	 * 	
	 * @return javax.swing.JToolBar	
	 */
	private   JToolBar getJToolBar16bit() {
//		if (jToolBar16bit == null) {
			jToolBar16bit = new JToolBar("Options");
			jToolBar16bit.setOrientation(1); //Vertical orientation
			jToolBar16bit.add(getJRadioButtonMenuButt16to8());	
			jToolBar16bit.add(getJRadioButtonMenuButt16Hidden());

			//jToolBar16bit.addSeparator();
			this.setButtonGroup16bit();	//Gruppieren der JRadioButtons
//		}
		return jToolBar16bit;
	}
	/**
	 * This method initializes jJToolBarBar	
	 * 	
	 * @return javax.swing.JToolBar	
	 */
	private   JToolBar getJToolBarPalette() {
//		if (jToolBarPalettte == null) {
			jToolBarPalettte = new JToolBar("Options");
			jToolBarPalettte.setOrientation(1); //Vertical orientation
			jToolBarPalettte.add(getJRadioButtonMenuButtPaletteToRGB());	
			jToolBarPalettte.add(getJRadioButtonMenuButtPaletteHidden());

			//jToolBarPalettte.addSeparator();
			this.setButtonGroupPalettte();	//Gruppieren der JRadioButtons
//		}
		return jToolBarPalettte;
	}
	/**
	 * This method initializes jJToolBarBar	
	 * 	
	 * @return javax.swing.JToolBar	
	 */
	private   JToolBar getJToolBarRGB() {
//		if (jToolBarRGB == null) {
			jToolBarRGB = new JToolBar("Options");
			jToolBarRGB.setOrientation(1); //Vertical orientation
			jToolBarRGB.add(getJRadioButtonMenuButtNTSC());			
			jToolBarRGB.add(getJRadioButtonMenuButtMeanRGB());			
			jToolBarRGB.add(getJRadioButtonMenuButtChR());
			jToolBarRGB.add(getJRadioButtonMenuButtChG());			
			jToolBarRGB.add(getJRadioButtonMenuButtChB());
			jToolBarRGB.add(getJRadioButtonMenuButtRGB2HSV());
			jToolBarRGB.add(getJRadioButtonMenuButtRGB2HLS());
			jToolBarRGB.add(getJRadioButtonMenuButtRGB2CIELAB());
			jToolBarRGB.add(getJRadioButtonMenuButtRGB2CIELUV());
			jToolBarRGB.add(getJRadioButtonMenuButtRGB2CIEXYZ());
			jToolBarRGB.add(getJRadioButtonMenuButtHSV2RGB());
			jToolBarRGB.add(getJRadioButtonMenuButtHLS2RGB());
			jToolBarRGB.add(getJRadioButtonMenuButtCIELAB2RGB());
			jToolBarRGB.add(getJRadioButtonMenuButtCIELUV2RGB());
			jToolBarRGB.add(getJRadioButtonMenuButtCIEXYZ2RGB());
			jToolBarRGB.add(getJRadioButtonMenuButtRGBHidden());

			//jToolBarRGB.addSeparator();
			this.setButtonGroupRGB();	//Gruppieren der JRadioButtons
//		}
		return jToolBarRGB;
	}
	private  void setButtonGroup8bit() {
		//if (ButtonGroup buttGroup8bit == null) {
			buttGroup8bit = new ButtonGroup();
			buttGroup8bit.add(butt8toRGB);
			buttGroup8bit.add(butt8to16);
			buttGroup8bit.add(butt8Hidden);
	}
	private  void setButtonGroup16bit() {
		//if (ButtonGroup buttGroup16bit == null) {
			buttGroup16bit = new ButtonGroup();
			buttGroup16bit.add(butt16to8);
			buttGroup16bit.add(butt16Hidden);
	}
	private  void setButtonGroupPalettte() {
		//if (ButtonGroup buttGroupPalettte == null) {
			buttGroupPalettte = new ButtonGroup();
			buttGroupPalettte.add(buttPaletteToRGB);
			buttGroupPalettte.add(buttPaletteHidden);
	}
	private  void setButtonGroupRGB() {
	//if (ButtonGroup buttGroupRGB == null) {
		buttGroupRGB = new ButtonGroup();
		buttGroupRGB.add(buttMeanRGB);
		buttGroupRGB.add(buttNTSC);
		buttGroupRGB.add(buttChR);
		buttGroupRGB.add(buttChG);
		buttGroupRGB.add(buttChB);
		buttGroupRGB.add(buttRGB2HSV);
		buttGroupRGB.add(buttRGB2HLS);
		buttGroupRGB.add(buttRGB2CIELAB);
		buttGroupRGB.add(buttRGB2CIELUV);
		buttGroupRGB.add(buttRGB2CIEXYZ);
		buttGroupRGB.add(buttHSV2RGB);
		buttGroupRGB.add(buttHLS2RGB);
		buttGroupRGB.add(buttCIELAB2RGB);
		buttGroupRGB.add(buttCIELUV2RGB);
		buttGroupRGB.add(buttCIEXYZ2RGB);
		buttGroupRGB.add(buttRGBHidden);		
	}
	

	//--------------------------------------------------------------------------------------------
	public void actionPerformed(ActionEvent e) {
		if ("reset".equals(e.getActionCommand())) {
			ParameterBlockJAI pbJAI = new ParameterBlockJAI("IqmConvert".toLowerCase());
			IqmTools.setCurrParameterBlockJAI(pbJAI);
			this.setParameterBlock(pbJAI);
			this.setParameterValues();
			//this.updateIqmOperatorGUI();  //if necessary here or some lines above
			this.reset();
		}
		if ("parameter".equals(e.getActionCommand())) {
			this.setParameterBlock();
			//this.updateIqmOperatorGUI();  //if necessary here or some lines above
		}

		//preview if selected
		if (this.isAutoPreviewSelected()){
			this.showPreview();
		}

	}
	//-------------------------------------------------------------------------------------------------
	public static void main() {

		SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				IqmConvertGUI gui = new IqmConvertGUI();
				gui.createIqmOperatorGUI();

			}
		});
	}
	
}//END
